package com.sf.fy.uav.applet.order.controller.task;

import com.sf.fy.uav.common.enums.ActivityProductTypeEnum;
import com.sf.fy.uav.common.response.order.task.GoodsTypeResponse;
import com.sf.fy.uav.common.response.order.task.GoodsTypeRsResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.good.controller.GoodsTypeRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 物资类型 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-04-13
 */
@RestController
@RequestMapping("/sys/goods-type/")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeRest goodsTypeRest;

    @Value("${max_weight.same_city:10}")
    private double sameCityMaxWeight;

    @Value("${max_weight.cross_city:15}")
    private double crossCityMaxWeight;

    @GetMapping("get-all")
    public Rs<GoodsTypeRsResponse> getCityGoodsType(@RequestParam Byte productType) {
        GoodsTypeRsResponse goodsTypeRsResponse = new GoodsTypeRsResponse();
        List<GoodsTypeResponse> goodsTypeResponses = goodsTypeRest.getCityGoodsType();
        goodsTypeRsResponse.setGoodsTypeResponses(goodsTypeResponses);
        if (productType.equals(ActivityProductTypeEnum.LOCAL.getCode())) {
            //同城
            goodsTypeRsResponse.setMaxWeight(sameCityMaxWeight);
        } else if (productType.equals(ActivityProductTypeEnum.CROSS_REGION.getCode())) {
            //跨城
            goodsTypeRsResponse.setMaxWeight(crossCityMaxWeight);
        }
        return Rs.success(goodsTypeRsResponse);
    }
}
